package vip.xumy.admin.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.admin.sys.pojo.Dictionary;

/**
 * @author:mengyxu
 * @date:2019年12月6日
 */

@Mapper
public interface IDictionaryMapper {

	@Results(id = "dictRM", value = { @Result(property = "id", column = "dict_id"),
			@Result(property = "code", column = "dict_code"), @Result(property = "name", column = "dict_name"),
			@Result(property = "desc", column = "dict_desc"), @Result(property = "parent", column = "dict_parent"),
			@Result(property = "status", column = "dict_status") })
	@Select({ "<script>", "SELECT * FROM dictionary ", "<where>", "<if test='id != null'> AND dict_id = #{id} </if>",
			"<if test='parent != null'> AND dict_parent = #{parent} </if>",
			"<if test='status != null'> AND dict_status = #{status} </if>", "</where>", "ORDER BY dict_id ASC",
			"</script>" })
	List<Dictionary> queryDict(Dictionary example);

	@Insert({ "INSERT INTO dictionary VALUES(#{id}, #{code}, #{name}, #{desc}, #{parent}, #{status})" })
	void insertDict(Dictionary dist);

	@Update({ "UPDATE dictionary SET dict_code = #{code}, dict_name = #{name}, dict_desc = #{desc},",
			"dict_parent = #{parent}, dict_status = #{status} WHERE dict_id = #{id}" })
	void updateDict(Dictionary dist);

	@Delete({ "DELETE FROM dictionary WHERE dict_parent = #{parent}" })
	void deleteDicts(String parent);

	@Delete({ "DELETE FROM dictionary WHERE dict_id = #{id}" })
	void deleteDict(Integer id);

}
